#include <stdio.h>
#include <stdlib.h>
#include "tpool.h"

tpool_t tp;

typedef struct data{
	int a;
	int b;
}data_t;

void* add_fun(void* arg){
	data_t* data = (data_t*)arg;
	int* re = my_malloc(sizeof(int));

	printf("start run task\n"); 
	*re = data->a + data->b ;
	return (void*)re;
}


void check_test(task_t* task){
	
	printf("data rval:%d\n", *((int*)task->rval));    
}

task_t* get_task(){

	data_t* data = my_malloc( sizeof(data_t));
	task_t* task;
	data->a = rand() % 10;
	data->b = rand() % 20;

    task= new_task(add_fun,data);
    return task;
}

int main(int argc, char* argv){

	int i;
	tpool_init(&tp,"test",4);
	start(&tp);

	for(i=0; i<10; i++){
    	schedule(&tp,get_task());
	}
    wait_all(&tp);	
}

